﻿package mortal.game.view.chat.chatPanel
{
    import __AS3__.vec.*;
    import com.gengine.utils.pools.*;
    import flash.display.*;
    import flash.text.engine.*;
    import mortal.component.gconst.*;

    public class ChatItem extends Sprite implements IDispose
    {
        private var _lineWidth:Number;
        private var _lineHeight:Number;
        private var _textBlock:TextBlock;
        private var _groupVector:Vector.<ContentElement>;
        public var textFilter:Array;
        private var _normalHeight:Number = 19;
        private var _faceHeigth:Number = 24;
        private var _vipFaceHeigth:Number = 48;
        private var _firstLineHeight:Number = 18;
        private var _totleHeight:int = 0;
        private var _col:int = 0;

        public function ChatItem()
        {
            this._groupVector = new Vector.<ContentElement>;
            return;
        }// end function

        public function setFilter(param1:Array) : void
        {
            this.textFilter = param1;
            return;
        }// end function

        public function init(param1:Vector.<ContentElement> = null, param2:int = 260, param3:Number = 21) : void
        {
            this._lineWidth = param2;
            this._groupVector = param1;
            this._lineHeight = param3;
            this.mouseEnabled = false;
            this.createChildren();
            return;
        }// end function

        public function createChildren() : void
        {
            if (!this._groupVector || this._groupVector.length == 0)
            {
                this.clear();
                return;
            }
            var _loc_1:* = new GroupElement(this._groupVector);
            this._textBlock = new TextBlock();
            this._textBlock.content = _loc_1;
            this.createTextLines(this._textBlock);
            return;
        }// end function

        private function createTextLines(param1:TextBlock) : void
        {
            this._totleHeight = 0;
            var _loc_2:Boolean = true;
            var _loc_3:* = param1.createTextLine(null, this._lineWidth);
            while (_loc_3)
            {
                
                if (this.textFilter)
                {
                    _loc_3.filters = this.textFilter;
                }
                else
                {
                    _loc_3.filters = [FilterConst.glowFilter];
                }
                var _loc_4:String = this;
                var _loc_5:* = this._col + 1;
                _loc_4._col = _loc_5;
                this.addChild(_loc_3);
                _loc_3.mouseEnabled = false;
                _loc_3.doubleClickEnabled = false;
                _loc_3.x = this._col <= 1 ? (0) : (5);
                this._totleHeight = this._totleHeight + this.getLineHeight(_loc_3);
                _loc_3.y = this._totleHeight + this.getTextLineYOffect(_loc_3);
                if (_loc_2)
                {
                    this._firstLineHeight = this.getLineHeight(_loc_3);
                    _loc_2 = false;
                }
                _loc_3 = param1.createTextLine(_loc_3, this._lineWidth);
            }
            return;
        }// end function

        private function isHaveFace(param1:TextLine) : Boolean
        {
            return param1.height > 20;
        }// end function

        private function isHaveVIPFace(param1:TextLine) : Boolean
        {
            return param1.height > 30 && param1.height < 90;
        }// end function

        private function getLineHeight(param1:TextLine) : Number
        {
            return this.isHaveVIPFace(param1) ? (this._vipFaceHeigth) : (this.isHaveFace(param1) ? (this._faceHeigth) : (this._normalHeight));
        }// end function

        private function getTextLineYOffect(param1:TextLine) : Number
        {
            return this.isHaveFace(param1) ? (-6) : (-3);
        }// end function

        public function getFirstLineHeight() : Number
        {
            return this._firstLineHeight;
        }// end function

        public function set groupVector(param1:Vector.<ContentElement>) : void
        {
            this._groupVector = param1;
            this.clear();
            this.createChildren();
            return;
        }// end function

        private function clearCell(param1:ContentElement) : void
        {
            var _loc_2:* = ChatCell.chatCellDic[param1] as ChatCell;
            _loc_2.dispose();
            delete ChatCell.chatCellDic[param1];
            return;
        }// end function

        private function clear() : void
        {
            var _loc_1:int = 0;
            var _loc_2:DisplayObject = null;
            var _loc_3:GroupElement = null;
            var _loc_4:ContentElement = null;
            if (this._textBlock && this._textBlock.content is GroupElement)
            {
                _loc_3 = this._textBlock.content as GroupElement;
                _loc_1 = 0;
                while (_loc_1 < _loc_3.elementCount)
                {
                    
                    _loc_4 = _loc_3.getElementAt(_loc_1);
                    this.clearCell(_loc_4);
                    _loc_1++;
                }
            }
            _loc_1 = this.numChildren - 1;
            while (_loc_1 >= 0)
            {
                
                _loc_2 = this.getChildAt(_loc_1);
                this.removeChildAt(_loc_1);
                _loc_1 = _loc_1 - 1;
            }
            this._totleHeight = 0;
            this._col = 0;
            return;
        }// end function

        public function get col() : int
        {
            return this._col;
        }// end function

        override public function get height() : Number
        {
            return this._totleHeight;
        }// end function

        public function get textBlock() : TextBlock
        {
            return this._textBlock;
        }// end function

        override public function addChild(param1:DisplayObject) : DisplayObject
        {
            return super.addChild(param1);
        }// end function

        public function get lineWidth() : Number
        {
            return this._lineWidth;
        }// end function

        public function set lineWidth(param1:Number) : void
        {
            this._lineWidth = param1;
            return;
        }// end function

        public function get lineHeight() : Number
        {
            return this._lineHeight;
        }// end function

        public function set lineHeight(param1:Number) : void
        {
            this._lineHeight = param1;
            return;
        }// end function

        public function dispose(param1:Boolean = true) : void
        {
            this.clear();
            x = 0;
            y = 0;
            this._groupVector = null;
            this._textBlock = null;
            this._lineWidth = 260;
            this._lineHeight = 21;
            this._normalHeight = 19;
            this._faceHeigth = 24;
            this._firstLineHeight = 18;
            this.textFilter = null;
            this.alpha = 1;
            this._totleHeight = 0;
            ObjectPool.disposeObject(this);
            return;
        }// end function

    }
}
